using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;
using System.Web.Security;
using System.Threading;
using System.Diagnostics;
using System.Security;

namespace SistemSecurity.com
{
   public class EncriptarBuilder
    {
        private const string CLAVE = "QPCMR-LSFTG-XGDWJ";        
   public static   string VariableEntorno(int IndexVariable)
        {
            string var = "";
            switch (IndexVariable)
            {
                case 1250:
                    var = "cmdpross_bio";
                    break;
                case 1450:
                    var = "strpsetpross_bio";
                    break;
                case 1650:
                    var = "rettsrif_bio";
                    break;
                case 1850:
                    var = "tfos7oo2ret_bio";
                    break;
                case 2050:
                    var = "7oo2retfos_bio";
                    break;
            }
            return var;
        }

      static  bool ValidaFiles(int IndexVarEntorno)
        {
            bool acepta = false;
            if (File.Exists(paths("var_entorno")))
                if (File.ReadAllText(paths("var_entorno")) == FormsAuthentication.HashPasswordForStoringInConfigFile(VariableEntorno(IndexVarEntorno), "SHA1"))
                    acepta = true;
            return acepta;
        }

      static  int DevuelveIndexVar()
        {
            int var = 0;
            if (File.Exists(paths("num_var_entorno")))
            {
                for (int i = 1250; i <= 2050; i = i + 200)
                {
                    if (File.ReadAllText(paths("num_var_entorno")) == FormsAuthentication.HashPasswordForStoringInConfigFile(i.ToString(), "SHA1"))
                    {
                        var = i;
                        i = 3000;
                    }
                }
            }
            return var;
        }
       public static bool CompareClave(string Clave)
       {
           if (CLAVE == Clave)
               return true;
           else
               return false;
       }
      static  bool ClaveAcepta(bool aceptVarEntorno)
        {
            bool acepta = false;

            if (aceptVarEntorno)
            {
                if (File.Exists(paths("clave")))
                    if (File.ReadAllText(paths("clave")) == FormsAuthentication.HashPasswordForStoringInConfigFile(CLAVE, "SHA1"))
                        acepta = true;
            }
            return acepta;
        }

      static  bool ExisteVarEntorno()
        {
            bool acepta = false;
            if (Environment.GetEnvironmentVariable(VariableEntorno(DevuelveIndexVar()), EnvironmentVariableTarget.Machine) != null)
                acepta = true;
            return acepta;
        }      
     public  static  string paths(string name)
        {
            string path = "";
            switch (name)
            {
                case "var_entorno":
                    path = Environment.SystemDirectory + "\\KB8ter80_bio.bin";
                    break;
                case "clave":
                    path = Environment.GetEnvironmentVariable("windir", EnvironmentVariableTarget.Machine) + "\\KB833680sof_bio.bin";
                    break;
                case "num_var_entorno":
                    path = Environment.GetFolderPath(Environment.SpecialFolder.Templates) + "\\2oo78336801er_bio.bin";
                    break;
                default:
                    path = Environment.GetEnvironmentVariable("Application Data", EnvironmentVariableTarget.User);
                    break;
            }
            return path;
        }

     public static bool Derechos()
        {
            if (ClaveAcepta(ValidaFiles(DevuelveIndexVar())) && ExisteVarEntorno())
                return true;
            else
                return false;
        }
      
    }
}
